package com.example.dormitory.service;


import com.example.dormitory.entity.*;
import com.example.dormitory.mapper.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class DormitoryNumberService {

    @Autowired
    private DormitoryNumberMapper dormitoryNumberMapper;

    public int create(DormitoryNumber dormitoryNumber) {
        return dormitoryNumberMapper.create(dormitoryNumber);
    }

    public int delete(String ids) {
        String[] arr = ids.split(",");
        int row = 0;
        for (String s : arr) {
            if(!StringUtils.isEmpty(s)){
                dormitoryNumberMapper.delete(Integer.parseInt(s));
            row++;
            }
        }
        return row;
    }

    public int delete(Integer id) {
        return dormitoryNumberMapper.delete(id);
    }

    public int update(DormitoryNumber dormitoryNumber) {
        return dormitoryNumberMapper.update(dormitoryNumber);
    }

    public int updateSelective(DormitoryNumber dormitoryNumber) {
        return dormitoryNumberMapper.updateSelective(dormitoryNumber);
    }

    public PageInfo<DormitoryNumber> query(DormitoryNumber dormitoryNumber) {
        if(dormitoryNumber != null && dormitoryNumber.getPage() != null){
            PageHelper.startPage(dormitoryNumber.getPage(),dormitoryNumber.getLimit());
        }
        return new PageInfo<DormitoryNumber>(dormitoryNumberMapper.query(dormitoryNumber));
    }

    public DormitoryNumber detail(Integer id) {
        return dormitoryNumberMapper.detail(id);
    }

    public int count(DormitoryNumber dormitoryNumber) {
        return dormitoryNumberMapper.count(dormitoryNumber);
    }
}
